home *** CD-ROM | disk | FTP | other *** search
/ Acorn Risc Technologies StrongARM CD-ROM / Acorn Risc Technologies StrongARM CD-ROM.iso / ftp / documents / appnotes / 001_015 / 012c / Text
Encoding:
Text File  |  1994-12-05  |  71.1 KB  |  1,760 lines

  1. -----------------------------------------------------------------------------
  2. 25th June 1992
  3. -----------------------------------------------------------------------------
  4. Support Group Application Note
  5. Number: 012
  6. Issue: 1
  7. Author:
  8. -----------------------------------------------------------------------------
  9.  
  10. How To Write A ViewStore Utility
  11.  
  12. -----------------------------------------------------------------------------
  13. Applicable Hardware: BBC B
  14.                      BBC B+
  15.                      BBC Master 128
  16.                      BBC Master Compact
  17.  
  18. Related Application Notes: ViewStore Hints and Tips
  19.  
  20.  
  21. -----------------------------------------------------------------------------
  22. Copyright (C) Acorn Computers Limited 1992
  23.  
  24. Every effort has been made to ensure that the information in this leaflet is 
  25. true and correct at the time of printing. However, the products described in
  26. this leaflet are subject to continuous development and improvements and
  27. Acorn Computers Limited reserves the right to change its specifications at
  28. any time. Acorn Computers Limited cannot accept liability for any loss or
  29. damage arising from the use of any information or particulars in this
  30. leaflet. ACORN, ECONET and ARCHIMEDES are trademarks of Acorn Computers
  31. Limited.
  32. -----------------------------------------------------------------------------
  33. Support Group
  34. Acorn Computers Limited
  35. Acorn House
  36. Vision Park
  37. Histon
  38. Cambridge       CB4 4AE
  39. -----------------------------------------------------------------------------
  40.  
  41. HOW TO WRITE A VIEWSTORE UTILITY
  42. by Mark Colton, author of VIEW, VIEWSHEET AND VIEWSTORE
  43.  
  44. Since the available space for ROM code is limited to 16k, ViewStore has
  45. provision for extra programs or utilities that exist outside the ROM to be
  46. used.  ViewStore is supplied with several utilities that supplement the ROM,
  47. and has an interface built into it to allow utility programs to use routines
  48. inside the ROM.  Certain areas of memory are also allocated for use by
  49. utility programs.  Given the knowledge of the  interface and memory
  50. allocation, it is possible to write extra utilities for ViewStore.  The
  51. purpose of this document is to define the utility interface to enable third
  52. parties to write their own utilities.  A good knowledge of ViewStore and
  53. assembly language will be essential.
  54.  
  55. The Interface
  56.  
  57. Various routines within the ROM are available for use by utilities.  The
  58. routines provide the utility with the means to access format files and data
  59. records and indexes and assorted useful functions.  The ROM has a jump table
  60. at the beginning which directs calls to the various routines in the ROM.
  61.  
  62. As well as access to the ROM routines, the utility has memory allocated to
  63. it.  Three areas of memory are available to a utility:
  64.  
  65.         A section of zero page
  66.         A section of language absolute workspace
  67.         A section of main memory
  68.  
  69. The amount of zero page and language workspace available to a utility depend
  70. upon which ROM routines the utility is going to use.  The size and position
  71. of the piece of main memory available can only be  determined when the
  72. utility is run:  pointers to the start and end of the main workspace are
  73. passed when the utility is started.
  74.  
  75. The zero page, language workspace and main memory not available to the
  76. utility is used by the ViewStore ROM itself.  A utility should not alter
  77. this memory, but the addresses of some locations are defined to allow
  78. utilities to read useful parameters.
  79.  
  80. Utility Format
  81.  
  82. The format of a utility must conform to certain rules.  When a utility is
  83. located and loaded from the filing system, ViewStore relocates the code to
  84. run at a particular point in memory.  This point varies according to the
  85. size of the format file loaded and the MOS "high water mark".  On machines
  86. with second processors attached, ViewStore relocates the utility to run in
  87. the space left above the ROM: from &C000 to &F800.  Using this relocating
  88. system, ViewStore make optimum use of the memory available.
  89.  
  90.  
  91. Since it is not easy to write position independent code for the 6502, the
  92. ROM includes a relocating system.  The utility must provide certain
  93. information about itself to enable this system to work.  The format of a
  94. utility is as follows:-  
  95.         .start  JMP     code
  96.                 EQUW    bitmap-start
  97.                 EQUW    start
  98.                 EQUS    "version no/copyright string"
  99.  
  100.         .code           /utility code begins here
  101.  
  102.                         /end of utility code
  103.  
  104.         .bitmap         /relocation bitmap
  105.  
  106.                         /end of utility
  107.  
  108. The first word after the initial JMP gives the offset from the beginning of
  109. the utility to the relocation bitmap.
  110.  
  111. Since the utility is relocated after being loaded, the actual assembly
  112. address is not important, but ViewStore must be told at what address the
  113. utility has been assembled, so that it can calculate how much needs to be
  114. added or subtracted from the addresses to be relocated.  The second word
  115. after the JMP gives the assembly address.  This &2000 for most of the
  116. supplied utilities.
  117.  
  118. The version no/copyright string is not essential, but it's a good idea to
  119. include one so that you can identify the code.
  120.  
  121. The main hurdle for anyone writing their own utilities will be the
  122. generation of the relocation bitmap.  This identifies the addresses that
  123. must be relocated.  There is a bit in the bitmap for every byte of code in
  124. the utility, excluding the bitmap itself.  A bit set to zero indicates that
  125. an address is not to be relocated; a bit set to one indicates that an
  126. address is to be relocated.
  127.  
  128. It is only possible to relocate addresses using this system, not single
  129. bytes.  This means that it is not possible to set up or move addresses using
  130. immediate data:
  131.  
  132.                 LDA     #place
  133.                 STA     var
  134.                 LDA     #place AND &FF
  135.                 STA     var+1
  136.  
  137. is not allowed.  You must use the form:
  138.  
  139.                 LDA     plcew
  140.                 STA     var
  141.                 LDA     placew+1
  142.                 STA     var+1
  143.  
  144.    .placed      EQUW            place
  145.  
  146. In the bitmap, a bit which is set is taken to refer to a 16 bit address
  147. within the program; it is therefore impossible to have two adjacent bits set
  148. since the second bit it referring to the high byte of the address.
  149.  
  150. Given eight adjacent bytes, all represented by a single byte in the bitmap,
  151. the most significant bit in the bitmap byte corresponds to the first code
  152. byte, and the least significant bit to the last code byte.
  153.  
  154. As an example:  the first byte of a relocation bitmap always corresponds to
  155. the JMP and EQUW structure at the beginning of the utility.  Assuming that
  156. you have a copyright string (which contains no addresses to be relocated),
  157. the first byte of the bitmap should always be &44.  The bit string for this
  158. is:
  159.  
  160.          MSB         LSB
  161.  
  162.          0 1 0 0 0 1 0 0
  163.  
  164. The first three bits correspond to the three bytes of the JMP instruction. 
  165. The second two bytes of the JMP instruction contain the address to jump to,
  166. which must be relocated.  The first bit of the two bits for this address is
  167. therefore set.  The next two bits correspond to the bitmap offset word. This
  168. remains constant for any load address, so these two bits are zero.  The next
  169. two bits are for the assembly address, which will alter as the utility is
  170. relocated, and the first bit is a 1 accordingly.  The last bit is for the
  171. first byte of the copyright string; zero since this has no addresses to be
  172. relocated.
  173.  
  174. The bitmaps for the utilities which are supplied with ViewStore were
  175. generated automatically by an assembler which is not available on the
  176. market.  If you are going to write a utility for ViewStore, you must find a
  177. way of generating relocation bitmaps.  This could be done in one of three
  178. ways:
  179.  
  180.         1.     Generate it by hand
  181.         2.     Write a program to take an assembled utility and generate the
  182. bitmap
  183.         3.     Modify an assembler to generate relocation bitmaps
  184.         4.     Assemble it at two different addresses and write a program to
  185. compare the two resulting code files.  Those locations which have changed
  186. need a set bit in the bitmap.
  187.  
  188. For most people, the last option will be the simplest.
  189.  
  190. The Utility Environment
  191.  
  192. Most utilities will want to operate upon existing databases.  It is
  193. possible, though, to have a utility which does not operate on existing data,
  194. but creates data, or doesn't act on data at all.
  195.  
  196. An example of this is the SETUP utility, which creates blank databases.  It
  197. doesn't refer to any existing data.  Utilities which need to access either
  198. format files or data files must first check that a database has been loaded,
  199. and abort with an error message if there is no loaded database.
  200.  
  201. This is done by checking the location FILMOD.  If FILMOD is non-zero, then a
  202. database is loaded.  If zero, there is no database loaded.
  203.  
  204. The normal sequence of operation will be to load a database in ViewStore,
  205. with the LOAD command.  This loads the format file into memory, and locates
  206. the data file.  A utility is then started with the UTILITY command.  The
  207. utility can read the format file as it requires, and can open and process
  208. the information in the data file.  It can use a subset of data identified by
  209. the select file.
  210.  
  211. Once the utility is running, it can take control of the machine as it needs
  212. to, using the memory available to it, and the ROM routines as required.
  213.  
  214. Naming of Addresses
  215.  
  216. In this document, all location and routine addresses will be referred to by
  217. name.  Tables of addresses and values are at the end of the document.
  218.  
  219. You will notice that the names of a block of addresses being with "TEMP". 
  220. These locations are available for use by the utility as temporary storage,
  221. but some are used and altered by routines in the ROM.
  222.  
  223. Temporaries
  224.  
  225. The numbered temporaries are all either a single byte or two bytes long. 
  226. Those from TEMPFD to TEMP05 are all one byte long; those from TEMP06 to
  227. TEMP14 are all two bytes long.  The two byte temporaries are used to store
  228. and pass addresses; the single byte temporaries are used to store one byte
  229. quantities.
  230.  
  231. Often, values are passed to and from routines using temporaries, as well as
  232. registers in the CPU.  Many routines "corrupt" certain temporaries; a list
  233. of the temporaries a routine corrupts is given in a summary at the end.
  234. Utilities can use temporaries whenever they wish, but of course their use
  235. must not clash with any routines that you call in the ROM.
  236.  
  237. Entry Parameters
  238.  
  239. When the utility is started, the following data is provided:
  240.  
  241.    TEMP14           contains the start address of free main memory
  242.    VWSLIM           contains  the address of the byte after the last free
  243.                     byte in main memory
  244.  
  245. VWSLIM will not change while the utility is running, and the utility must
  246. not alter VWSLIM.  TEMP14 may be altered by a ROM call, so it is best to
  247. store it somewhere else for later reference.
  248.  
  249. The utility is called with a JSR instruction, and ViewStore expects the
  250. utility to hand back control, when it is finished, with an RTS instruction.
  251.  
  252.         .start  TSX
  253.                 STX          stksav
  254.                 .
  255.                 .
  256.         .error  LDX          stksav
  257.                 TXS
  258.                 RTS
  259.  
  260. Zero Page
  261.  
  262. Zero page is divided up into four areas of different types:
  263.  
  264.    ViewStore variables  read only for utilities. Below &50.
  265.  
  266.    Temporaries          TEMPFD-TEMP 
  267.   
  268.    Floating point       FACCxxand FWRKxx. Start at &6B. read/write for
  269.    accumulators         utilities; if the floating point calls are not used
  270.                         by the utility. this area can be used as general 
  271.                         workspace.
  272.  
  273.    General workspace    VWSXTZ-&8F inclusive.
  274.  
  275. Language Workspace
  276.  
  277.    LWORK                                16 byte parameter block used by ROM
  278.                                         routines.
  279.    FBLOCK                               27 byte filename work area.
  280.    LINBUF                               256 byte work area used by one or 
  281.                                         two ROM routines.
  282.    VWSXTL-VWSITL                        area used by ISAM index system. Can 
  283.                                         be used as general workspace if the
  284.                                         utility is not using indexes.
  285.    General workspace                    VWSITL-&7FF inclusive.
  286.  
  287.  
  288. ROM Routines
  289.  
  290. I will describe the ROM routines in the categories that they fall into.  The
  291. routine addresses and parameters are summarised in table 1.  All routines
  292. should be called with a JSR instruction, except for CALUTI which should be
  293. called with a JMP instruction, since returning control to the utility is not
  294. usually sensible as the new utility will overwrite the old one in memory.
  295.  
  296.  
  297. Data File Control
  298.  
  299. These routines give the utility access to the database data file, using the
  300. current select file if required.  It is only possible to read sequentially
  301. through the data file using these calls, but the data will be returned in
  302. sorted order if the selected data was sorted.
  303.  
  304. The utility should not close the intermediate file if it uses it.  This is
  305. done automatically when control is returned to the ROM.
  306.  
  307.         INIIMF          Initialise data sequence.  Called to start the data
  308.                         reading sequence.
  309.         MXTIMF          Get next from data sequence. Each call returns the
  310.                         next data record in the sequence.
  311.  
  312.  
  313. INIIMF
  314.  
  315. This routine is called to initiate a sequence of data transfers.  It opens
  316. the main data file, and stores its handle in the location EFILE.  According
  317. to the state of the carry flag on entry, it asks the user if he wishes to
  318. use a select file.  The user responds with a yes or no, and ViewStore opens
  319. the select file (S.database) accordingly.  After this, the select file is
  320. transparent to the utility; repeated calls to NXTIMF will either return all
  321. the records in the data file if the select file is not being used, or the
  322. subset of records in the select file, if specified.
  323.  
  324. On entry:               CC      Don't ask "Use select file (Y,N)?" question.
  325.                         CS      Ask select file question.
  326.  
  327. On exit:                VC      No error.
  328.                         VS      Error; error code in A.
  329.  
  330. NXTIME
  331.  
  332. After starting the sequence with a call to INIIMF, repeated calls to MXTIMF
  333. return the records in the data file one by one.
  334.  
  335. On entry:               A               low byte of address to store record.
  336.                         Y               high byte of address to store
  337.                                         record.
  338.                         TEMP13          address of the byte after the last
  339.                                         byte available to store the record.
  340.  
  341. On exit:                VC              No error.
  342.                         VS              Error; error code in A.
  343.  
  344.                         CC              Not end of file.
  345.                         CS              End of file (returned on the call
  346.                                         after the last record has been
  347.                                         processed).
  348.  
  349. Errors
  350.  
  351. Many of the ROM routines can return an error status.  An error is usually
  352. indicated by either the Carry flag (C), or the Overflow flag (V).  When an
  353. error is indicated, the error code is in the A register.  To report the
  354. error to the user, call the routine REPERL with this code A.  The various
  355. error codes and messages are summarised later.  A utility can use a ROM
  356. error message by loading the appropriate code into A, and calling REPERL.
  357.  
  358. All file calls have the same error trapping system: after a call, V is set
  359. to indicate an error, clear if there was no error.  This includes errors
  360. causing a BRK, that is control is returned to the calling routine even when
  361. a BRK is occurred.  When you call REPERL with the returned error code, the
  362. BRK message will be reported as normal.
  363.  
  364. REPERL
  365.  
  366. Reports the error message for the error code in A:
  367.  
  368. On entry:         A             contains error code.
  369.  
  370. On exit:          A,X,Y         undefined.
  371.  
  372.  
  373. Field and Record Control
  374.  
  375. Much of ViewStore's manipulation is on fields and records; accordingly,
  376. there are several routines available to make this easier.  There are some
  377. routines to locate fields in the header, format file or current record;
  378. routines to compare field values; and routines to find the size of a given
  379. field.
  380.  
  381. Most of these routines use the two temporaries TEMP06 and TEMP07. TEMP06
  382. points to either a field within the format file, or a field within the
  383. current record. TEMP07 points to a field within the current record.  The Y
  384. indirect indexed addressing mode is used in conjunction with these
  385. temporaries to access the field contents: the temporary points to the
  386. beginning of the field, and the Y register gives the offset from there.
  387.  
  388. Remember that the format file itself is in the same format as a data file.
  389. The same routines are used to process information in records of the database
  390. as in the format file itself.  For each field in the database, there is a
  391. record in the format file, and this record details the characteristics of
  392. its corresponding field in the database.  The header record is the first
  393. record in the format file.
  394.  
  395. Data Format
  396.  
  397. The data format is summarised in table 10 at the end of the document.  All
  398. fields in ViewStore are stored in ASCII, even numbers and dates; each field
  399. ends with an end of field marker; each record ends with an end of record
  400. marker; and the file ends with an end of file marker; after the end of file
  401. marker, the file is padded up to the physical end of file with null
  402. characters.  If you are processing a field's contents, you should test for
  403. the end of field using the CHKEOF and CHKEOR routines.  These routines set
  404. the flags according to the character that they find.  Don't check for the
  405. character value explicitly.
  406.  
  407. Generally, when you make a call to a routine that locates a field, the x
  408. register indicates where the field is to be found:
  409.  
  410.         X=0             Field in header; A has field number.
  411.         X=1 to 254      Field in format file; X gives format file record
  412.                         number; A has field number.  The field numbers of
  413.                         the various format file fields are summarised below.
  414.         X=225           Field in current record; A has field number; Y has
  415.                         record number.
  416.  
  417. Fields within a record are numbered from 1 to 254.  If you ask for a field
  418. which is not in the record, the routine will return with the Carry flag set. 
  419. Whereas ViewStore knows where the format file is located, the address of the
  420. current record could be anywhere, and before fields within the current
  421. record can be accessed, you must tell ViewStore its address with the SETDPS
  422. routine.
  423.  
  424.         GETFLD          General field locate routine; can locate a field in                          the header, format file or current record.
  425.         GETFRC          Find the address of a field in the current record.
  426.         GETXFL          Return first non-space character of a field in the A
  427.                         register, folded to upper case if applicable.
  428.         SETDPS          Set the address of the beginning of the current
  429.                         record.
  430.         CHKEOF          Check the character in the A register for an end of
  431.                         field character.
  432.         CHKEOR          Check the character in the A register for an end of
  433.                         record character.
  434.         SIZFLD          Return the size of a given field.
  435.         CMPFLD          Compare two fields of the same type and set the
  436.                         flags.
  437.         SCHFLD          Return the number of a field, given its name.
  438.         SCHFLN          Return the next field number, given a name, for an 
  439.                         ambiguous name specification.
  440.  
  441.         GETWID          Return the display width for a particular field.
  442.         GETKYW          Return the key width for a particular field.
  443.         CALSBN          Calculate the number of spaces required to be output
  444.                         before a numeric field to right justify it within
  445.                         the display width.
  446.  
  447. GETFLD
  448.  
  449. This routine locates a field in either the database header, the format file
  450. or the current record.  If the field is in the current record, the address
  451. of the first character of the field is set into TEMP06 and also into TEMP07. 
  452. If the field is in the format file, TEMP07 is left unaltered, and the
  453. address of the field is put into TEMP06.
  454.  
  455. If X is equal to 255, then the routine uses the value in the Y register to
  456. locate a record in a list of current records.  The list of records is
  457. numbered from 0 onwards.  The usual way to use this part of the routine will
  458. be with Y set to zero, in order to locate a field within a single current
  459. record.  If you are using a list of records, then you must not set Y to too
  460. high a value, so that the routine runs off the end of the list, unless you
  461. have an end of file marker after the last record.
  462.  
  463. Before you use this routine, you must have set the position of the first
  464. record in the list by using the SETDPS call.
  465.  
  466. On entry:               A               field number of field to locate;
  467.                                         field start at 1.
  468.                         X=0             find field in header record.
  469.                         X=1 to          find field in format file record; X
  470.                         X=254           gives the number of the format file
  471.                                         record.
  472.                         X=255           find field in list of current
  473.                                         records; Y has the number of the
  474.                                         record to search, starting at zero.
  475.                         Y               only significant if X=255.
  476.  
  477. On exit:                CS              field or record not found; TEMP06
  478.                                         (and TEMP07 if X=255) point to the
  479.                                         end of record marker if field not
  480.                                         found, the end of file marker if
  481.                                         record not found.
  482.                         CC              field and record found; TEMP06
  483.                                         points to the beginning of the
  484.                                         field; if the call was made with
  485.                                         X=255 then TEMP07 also points to the
  486.                                         beginning of the field.
  487.                         A,Y             undefined.
  488.                         X               preserved.
  489.  
  490.  
  491. GETFRC
  492.  
  493. This call first sets X to 255, and then calls the GETFLD routine.  The entry
  494. and exit conditions are as for GETFLD when X-255, except that X will always
  495. return set to 255.
  496.  
  497.  
  498. GETXFL
  499.  
  500. GETXFL returns the first non-space character in a field, folded to upper
  501. case if alphabetic.  It is intended primarily for reading the value of
  502. single character fields in the format file, such as the "Field type" field.
  503.  
  504. GETXFL first calls the routine GETFLD.  The entry conditions are the same as
  505. GETFLD.  If the call to GETFLD fails, ie the Carry flag is set, then the A
  506. register is cleared, and the routine ends.  If the field is  found, then the
  507. first character of the field is returned, folded to upper case if
  508. alphabetic.  If the field is blank, then the end of field marker will be
  509. returned.
  510.  
  511. On entry:               See GETFLD
  512.  
  513. On exit:                        TEMP06 and TEMP07 set as for GETFLD.
  514.                         CS      field or record not found, as GETFLD; A set                                  to zero.
  515.                         CC      field found; A contains first non-space
  516.                                 character, folded to upper case if
  517.                                 alphabetic.
  518.                         X,Y     See GETFLD.
  519.  
  520. SETDPS
  521.  
  522. This routine stores the address of the records to be used when using one of
  523. the field locate routines with X set to 255.  It should be called whenever
  524. the address of one of the records in the list or of one of the fields in the
  525. records has altered.  It need not be called if none of the fields has moved,
  526. since ViewStore will keep track of its position in the list of records, and
  527. move backwards or forwards as necessary to find the field you have asked
  528. for.
  529.  
  530. If you are reading records one by one using the NXTIMF call, for example,
  531. then you must call SETDPS with their address of the record for each record
  532. that you read: the alignment of the fields will alter for each record.
  533.  
  534. On entry:       A               contains low byte of the address of the first
  535.                                 record in the list.
  536.                 Y               contains the high byte of the address of the 
  537.                                 first record in the list.
  538.  
  539. On exit:        A,X,Y           undefined.
  540.  
  541.  
  542. CHKEOF
  543.  
  544. CHKEOF checks the character in the A register for an end of field marker. 
  545. It should be used rather than checking for the character explicitly since it
  546. handles classes of characters rather than single values.  Generally, it is
  547. not necessary to detect illegal characters explicitly, it is enough to
  548. detect them as an end of field marker.
  549.  
  550. On entry:       A               contains character value to be checked.
  551.  
  552. On exit:        EQ              end of field.
  553.                 CS              end of record (EQ also set).
  554.  
  555.                 VS              illegal character (EQ also set).
  556.                 A,X,Y           preserved.
  557.  
  558.  
  559. CHKEOR
  560.  
  561. CHKEOR  checks the character in the A register for an end of record marker.
  562.  
  563. On entry:               A               contains character to be checked.
  564.  
  565. On exit:                EQ              end of record.
  566.                         CS              end of file (EQ also set).
  567.                         VS              space character (EQ also set).
  568.                         A,X,Y           preserved.
  569.  
  570.  
  571. SIZFLD
  572.  
  573. SIZFLD is provided to allow you to determine the size of a field.  First of
  574. all you should locate the field, using one of the field locator routines
  575. such GETFLD, which set up TEMP06.  Then call SIZFLD.
  576.  
  577. On entry:               TEMP06          points to the beginning of the
  578.                                         field.
  579.  
  580. On exit:                A,Y             have length of field in characters.
  581.                         EQ              zero length field.
  582.                         X               preserved.
  583.                         TEMP06          preserved.
  584.  
  585.  
  586. CMPFLD
  587.  
  588. CMPFLD compares the values of two fields of the same type, and sets the 6502
  589. flags register like the CMP instruction.  TEMP07 points to the first field
  590. (equivalent to the contents of the 6502 A register in the CMP instruction),
  591. and TEMP06 points to the second field.  If the two fields being compared are
  592. strings, then wildcards are allowed in the second string.
  593.  
  594. On entry:       A               contains the field type: A, N, D or Y; must
  595.                                 be in upper case.
  596.                 TEMP07          points to field 1.
  597.                 TEMP06          points to field 2.
  598.  
  599. On exit:        VS              error in one of the fields supplied: eg
  600.                                 illegal date; result not valid.
  601.                 C flag          set according to compare.
  602.                 Z flag          set according to compare.
  603.                 A,X,Y           undefined.
  604.  
  605.  
  606. SCHFLD
  607.  
  608. SCHFLD is used to find the number of a field, given its name.  It searches
  609. the list of fields in the format file until it finds one that fits the name
  610. given.  The name that you specify can obtain wild cards: the single wildcard
  611. "?", and the multiple wildcard "*" are both allowed.  SCHFLD will always
  612. return the first field in the format file that fits the name you have given. 
  613. You can either continue searching for more fields by using the SCHFLD call
  614. described next.
  615.  
  616. The name of the field is set up in the 16 byte LWORK area.  It should be
  617. terminated by a null, or an end of field marker.  It must not be longer then
  618. 16 bytes, including the delimiter.
  619.  
  620. On entry:       LWORK           contains name to search for; maximum of 16
  621.                                 bytes including delimiter; delimiter null
  622.                                 or end of field marker; wildcards "?" and
  623.                                 "*" valid.
  624.  
  625. On exit:        CS              no field found to match the name; A has
  626.                                 error code.
  627.                 CC              field found OK; field number in X.
  628.  
  629.  
  630. SCHFLN
  631.  
  632. After calling SCHFLD, you can search for other fields which also fit the
  633. field specification that you gave given, by making repeated calls to SCHFLN. 
  634. Before you call SCHFLN, you must have called SCHFLD first, to start the
  635. sequence, and this call must have successfully found a field.
  636.  
  637. You can keep calling SCHFLN until the call returns with the Carry flag set
  638. to indicate that it has found no more fields.
  639.  
  640. On entry:               Must have called SCHFLD first, and this must have
  641.                         returned with the Carry flag clear.
  642.            A            Contains field number to start searching 
  643.                         from.  This should be one more than the last value
  644.                         that SCHFLD or SCHFLN returned in X.
  645.  
  646. On exit:   CS           no more fields found; A has error code  (report only
  647.                         if required).
  648.            CC           field found; field number in X.
  649.  
  650.  
  651. GETWID
  652.  
  653. GETWID returns the display width of a field, as defined in the format file. 
  654. If there is no display width defined, a series of defaults comes into
  655. action.
  656.  
  657. Display width defined                   Display width  
  658. No display width, Sheet mode            18 
  659. No display width, Card mode             0 
  660.  
  661. On entry:               X               contains number of field for which
  662.                                         width is required.
  663.  
  664. On exit:                CS              field doesn't exit.
  665.                         CC              field found; A has display width.
  666.                         X               preserved.
  667.                         Y               undefined.
  668.  
  669.  
  670. GETKYW
  671.  
  672. This routine finds the key width for a given field.  It uses the value
  673. defined in the format file, if any; otherwise a system of defaults operates:
  674.  
  675. Key width defined                               Key width  
  676. No key width, display width defined             Display width
  677. No key width or display width                   10
  678.  
  679. On entry:               X       contains number of field for which width is
  680.                                 required.
  681.  
  682. On exit:                CS      field doesn't exist.
  683.                         CC      field found; A has already width.
  684.                         X       preserved.
  685.                         Y       undefined.
  686.  
  687.  
  688. GETKYW
  689.  
  690. This routine finds the key width for a given field.  It uses the value
  691. defined in the format file, if any; otherwise a system of defaults operates:
  692.  
  693. Key width defined                               Key width
  694. No key width, display width defined             Display width
  695. No key width or display width                   10
  696.  
  697. On entry:       X               contains the field number for which the key
  698.                                 width is required.
  699.  
  700. On exit:        A               contains key width; if field doesn't exist,
  701.                                 a default key width of 10 is returned.
  702.                 X               preserved.
  703.                 Y               undefined.
  704.  
  705.  
  706. CALSBN
  707.  
  708. This routine is used when displaying numeric fields, to calculate the number
  709. of spaces to be output before the number in order to right justify the
  710. number within its field width.  This also takes into account the decimal
  711. places specified in the format file.
  712.  
  713. On entry:       X               contains the field number.
  714.                 TEMP07          points to the beginning of the field in
  715.                                 question.
  716.                 TEMP03          contains the field display width, as
  717.                                 returned by the GETWID routine.
  718.  
  719. On exit:        A               gives number of spaces to output, zero if
  720.                                 the number is wider than the field, or there
  721.                                 are too many decimal places.
  722.                 X               undefined.
  723.                 Y               undefined.
  724.                 TEMP03          preserved.
  725.                 TEMP07          preserved.
  726.  
  727.  
  728. File Control
  729.  
  730. File handling in ViewStore is centred around three things: error handling,
  731. FBLOCK and prefixes.  Since the error handling provided by the normal filing
  732. system interface provided is completely unsatisfactory for a program such as
  733. ViewStore, I have developed a system which gives control of what happens
  734. after a disc or filing system error.  For the utility writer, this system is
  735. transparent: you can forget about it as long as you use the calls provided,
  736. and don't call the filing system directly.  If you do this, you can forget
  737. all about BRK errors and handlers.
  738.  
  739. The system is the same for all file calls: the state of the Overflow (V)
  740. flag indicates after a call whether an error has occurred.  If there has
  741. been an error, then the V flag is set, and the A register contains the error
  742. code.  If you detect an error, you should unravel yourself from any
  743. routines, report the error by calling the REPERL routine, and then close any
  744. files that you have opened yourself, before returning to control of the ROM. 
  745. You shouldn't close the intermediate file: this is done automatically when
  746. control is passed back to the ROM.
  747.  
  748.  
  749. Filenames
  750.  
  751. FBLOCK is a small of memory used to store and manipulate filenames.  Several
  752. routines are provided which work on the filename in FBLOCK, altering
  753. directories and prefixes.
  754.  
  755. A filename in ViewStore is made up of three parts:
  756.  
  757.         Prefix
  758.         Directory
  759.         Name
  760.         
  761. ViewStore maintains a list of the current prefixes for each different file
  762. type: data; format; sort and so on.  A routine which adds a specified prefix
  763. to a directory and name stored in FBLOCK is available.  The maximum length
  764. of a prefix is 13 characters, excluding delimiter.  The current prefixes can
  765. only be altered with the PREFIX command in ViewStore's Command Mode.
  766.  
  767. ViewStore considers directories to be single character; of course the prefix
  768. can include multiple character directories, but the filenames of data and
  769. format files, for example, begin with directories, and these are always
  770. single character directory names, whatever the filing system.  Directories
  771. must be separated from the name itself by a dot, making the total size of
  772. the directory section of a filename 2 characters.
  773.  
  774. The name part of the filename can be up to 10 characters long.  This does
  775. not include the directory and separator, or the delimiter.  Names are always
  776. delimited with a Carriage Return character.
  777.  
  778. Part            Max. Size (exc. delimiter)      Example
  779.  
  780. Prefix          13                              :2.
  781. Director        2                               d.
  782. Name            10                              datafile
  783.  
  784. MOVFBK          Moves a filename from the store area into FBLOCK. 
  785. MOVNAY          Moves a filename out of FBLOCK into the store area. 
  786. CHKDIR          Checks for the presence of a directory in a filename in
  787.                 FBLOCK, and returns the directory character, if there is
  788.                 one. 
  789. SETDIR          Sets a directory into a filename in FBLOCK. 
  790. STXPRE          Stores the required prefix with a filename in FBLOCK. 
  791. OPFILE          Gives access to the filing system OSFIND call. 
  792. OSHCAL          Gives access to the filing system OSFILE call. 
  793. XOSARG          Vector with error trapping to OSARGS. 
  794. XOSBGE          Vector with error trapping to OSBGET. 
  795. XOSBPU          Vector with error trapping to OSBPUT. 
  796. XOSCLS          Vector  with error trapping to OSFIND with A=0; used to
  797.                 close a file.
  798. XOSGBP          Vector with error trapping to OSGBPB. 
  799. CALUTI          Loads and runs a utility format file.
  800.  
  801.  
  802. MOVFBK
  803.  
  804. MOVFBK moves a filename from ViewStore's list into FBLOCK.  A summary of the
  805. filenames available and their offsets is given in table 8.  Filenames are
  806. not stored with prefixes attached, but they do include the directory.  You
  807. must use the routine STXPRE to add a prefix to the filename once it has been
  808. moved to FBLOCK, before calling one of the file routines.
  809.  
  810. On entry:       Y       contains the offset of the filename to be 
  811.                         moved into FBLOCK.
  812.  
  813. On exit:        A,X,Y   undefined.
  814.  
  815.  
  816. MOVNAY
  817.  
  818. This routine is the inverse of MOVFBK; it moves a filename from FBLOCK into
  819. ViewStore's list of names.  The filename in FBLOCK should not include the
  820. prefix when this routine is called.  The list of filename offset values is
  821. given in table 8.
  822.  
  823.  
  824. On entry:       X               contains the offset of the filename area in 
  825.                                 which the name currently in FBLOCK is to be
  826.                                 stored.
  827.  
  828. On exit:        A,X,Y           undefined.
  829.  
  830.  
  831. CHKDIR
  832.  
  833. CHKDIR checks whether the filename in FBLOCK has a directory, and if it
  834. does, it returns the directory.  The filename should not include the prefix
  835. when this routine is called.
  836.  
  837. On entry:                               filename to check in FBLOCK.
  838.  
  839. On exit:                CS              filename contains directory; 
  840.                                         directory character  found returned
  841.                                         in A; offset from beginning of
  842.                                         FBLOCK to the directory character is
  843.                                         in X.
  844.                         CC              no directory found.
  845.                         Y               undefined.
  846.  
  847.  
  848. SETDIR
  849.  
  850. SETDIR forces a directory into the filename in FBLOCK.  It doesn't matter
  851. whether the filename there contains a directory or not; SETDIR will make
  852. space for it.  The filename must not include a prefix when SETDIR is called.
  853.  
  854. On entry:       A               contains directory character to set into name
  855.                                 in FBLOCK.
  856.  
  857. On exit:        A,X,Y           undefined.
  858.  
  859.  
  860. STXPRE
  861.  
  862. This is the routine that you use to add a prefix to a name.  The name
  863. itself, including directory, should be in FBLOCK.  Normally, adding the
  864. prefix to a name is the last thing you do before calling the filing system
  865. to do some operation on the file: opening or deleting the file, for example. 
  866. Names themselves should be stored without prefix attached, the prefix being
  867. added only when calling the filing system itself.
  868.  
  869. A list of the prefix offsets for different file types is given in table 7.
  870.  
  871. On entry:       X               contains the offset of the prefix required.
  872.  
  873. On exit:        A,X,Y           undefined.
  874.  
  875.  
  876. OPFILE
  877.  
  878. OPFILE is an equivalent of the filing system "OSFIND" call, used for opening
  879. files.  It assumes, however, that the filename is ready in FBLOCK.  OPFILE
  880. cannot be used to close a file, as OSFIND can; use the XOSCLS call to close
  881. a file.  OPFILE also uses the ViewStore error trapping system.        
  882.  
  883. On entry:       A               contains file open code, as for OSFIND; eg.
  884.                                 &40 is open for input.
  885.  
  886. On exit:        VS              error occurred; error code in A.
  887.                 VC              no error occurred; file handle is in both A
  888.                                 and Y registers; usual OSFIND error of file
  889.                                 handle being zero when the file can't be 
  890.                                 found is trapped:  V is set, and the
  891.                                 ViewStore "File not found" error code is in
  892.                                 A; Y is zero.
  893.                 X               undefined.
  894.  
  895.  
  896. OSHCAL
  897.  
  898. OSHCAL gives the utility access to the filing system OSFILE routine.  It
  899. uses the OSFARA area as its control block.  Note that this spills over into
  900. the LWORK area, which will be corrupted after an OSHCAL call.  OSHCAL
  901. assumes that the filename (when required) is set up in FBLOCK.  OSHCAL also
  902. sets the high order addresses into the control block at OSFARA +4 and +5;
  903. +&C and +&D; and at +&10 and +&11.  ViewStore error trapping is also
  904. enabled.
  905.  
  906. On entry:       A               contains reason code as for normal OSFILE
  907.                                 (see filing system manual).
  908.                 OSFARA          set up with whatever the reason code action
  909.                                 requires, eg. start and end addresses for
  910.                                 file save.
  911.  
  912. On exit:        VS              error occurred; error code in A.
  913.                 VC              completed successfully; file type in A when
  914.                                 relevant.
  915.                 X,Y             undefined.
  916.  
  917.  
  918. XOSARG
  919.  
  920. XOSARG is equivalent to OSARGS, except that ViewStore error handling is
  921. enabled.
  922.  
  923. On entry:                       See filing system manual for OSARGS.
  924.  
  925. On exit:        VS              error occurred; error code in A.
  926.                 VC              no error; see filing system manual for
  927.                                 results.
  928.  
  929.  
  930.  
  931. XOSBGE
  932.  
  933. XOSBGE is equivalent to OSBGET, except that ViewStore error handling is
  934. enabled.
  935.  
  936. On entry:                       See filing system manual for OSBGET.
  937.  
  938. On exit:        VS              error occurred; error code in A.
  939.                 VC              no error; see filing system manual for
  940.                                 results.
  941.  
  942.  
  943. XOSBPU
  944.  
  945. XOSBPU is equivalent to OSBPUT, except that ViewStore error handling is
  946. enabled.
  947.  
  948. On entry:                       see filing system manual for OSBPUT.
  949.  
  950. On exit:        VS              error occurred; error code in A.
  951.                 VC              no error; see filing system manual for
  952.                                 results.
  953.  
  954.  
  955. XOSCLS
  956.  
  957. XOSCLS is equivalent to OSFIND with A=0, in order to close a file. 
  958. ViewStore error trapping is also enabled.
  959.  
  960. On entry:       Y       contains handle of file to be closed.
  961.  
  962. On exit:        VS      error occurred; error code in A.
  963.                 VC      file closed successfully.
  964.                 X,Y     undefined.
  965.  
  966.  
  967. XOSGBP
  968.  
  969. XOSGBP is equivalent to OSGBPB, except that ViewStore error handling is
  970. enabled.
  971.  
  972. On entry:                       See filing system manual for OSGBPB.
  973.  
  974. On exit:        VS              error occurred; error code in A. 
  975.                 VC              no error; see filing system manual for 
  976.                                 results.                                
  977.  
  978.  
  979. CALUTI
  980.  
  981. CALUTI is provided to allow utilities to call other programs stored in
  982. utility file format.  The SELECT utility, which is provided with ViewStore,
  983. uses this call to call the SORT program when it is required.  Parameters can
  984. be passed between the programs using temporaries, or other memory space. 
  985. The CALUTI call can be thought of as the logical equivalent of the Basic
  986. CHAIN statement. The utility should exit under the prefix given for
  987. utilities; CALUTI applies the utility prefix to the name given
  988. automatically.  If the utility is not found, the "Insert utility disc and
  989. hit a key" message will be generated, and ViewStore will wait until a key is
  990. pressed before continuing.
  991.  
  992. On entry:       A               contains low byte of address of name of 
  993.                                 utility to be loaded.  Name must be
  994.                                 terminated by Carriage Return.
  995.                 Y               contains high byte of address of name of 
  996.                                 utility to be loaded.
  997.                 TEMP14          contains the address of the first byte of
  998.                                 free memory that the utility being loaded is
  999.                                 to use.  This will normally be the same
  1000.                                 value as passed to the initial utility.
  1001.  
  1002. On exit:        VS              error occurred; error code in A.  Otherwise, 
  1003.                                 control is passed to the new utility.
  1004.  
  1005.  
  1006. Floating Point
  1007.  
  1008. Unfortunately, a discussion of floating point is outside the scope of this
  1009. document.  However, certain of the key routines in a floating point package
  1010. are in the ROM itself, and entry points to these routines are provided.  
  1011. The REPORT utility which is provided with ViewStore uses these routines, and
  1012. implements many more inside itself.  The routine most obviously missing from
  1013. this set is a routine to output a floating point number in ASCII.  If you
  1014. wish to do this, you will have to work out how to do it yourself.
  1015.  
  1016. I can refer you to the "Advanced Basic Rom User Guide", published by the
  1017. "Cambridge Microcomputer Centre", which contains useful information about
  1018. the floating point package in Basic, and how it works.  The floating point
  1019. in ViewStore works in the same way.
  1020.  
  1021. Remember that there is no need to understand floating point to write a
  1022. utility, since the date in ViewStore files is stored in ASCII format, not as
  1023. floating point numbers.  Use of floating is only necessary when you wish
  1024. your utility to provide floating point arithmetic.
  1025.  
  1026. The two accumulators, FWRK and FACC are in zero page.  If you are not using
  1027. the floating point package in your utility, you can use the zero page
  1028. allocated to the accumulators for your own purposes.
  1029.  
  1030.  
  1031.         FONE         Sets FACC to value of one.
  1032.         FTENFX       Multiplies FACC by 10 (not normalised).
  1033.         FTENGQ       Divides FACC by 10 (not normalised).
  1034.         FADDWI       Adds FACC and FWRK; answer in FACC, not rounded.
  1035.         FTENX        Multiplies mantissa by 10.
  1036.         FRDDK        Reads in ASCII number to FACC.  Low byte of address of
  1037.                      string in A; high byte of address of string in Y.
  1038.         FTST         Tests number of FACC and sets flags.
  1039.         FNEG         Swaps sign of number in FACC.
  1040.         FCLR         Sets FACC to zero.
  1041.         FADDW        Adds FACC and FWRK; answer in FACC, rounded.
  1042.         FDIVA        Divides FACC by FWRK; answer in FACC.
  1043.         FMULX        Multiples FACC by FWRK; answer in FACC. 
  1044.  
  1045.  
  1046. General
  1047.  
  1048. These routines are an assortment of useful subroutines for which entry
  1049. points are provided.
  1050.  
  1051.         GETDEC       Get a decimal number.
  1052.         KINCH        Flush keyboard buffer, and get an input character.
  1053.         MULPLY       Multiply two single byte integers.
  1054.         OUTDEC       Output a decimal number.
  1055.         PSTRNG       Output a string.
  1056.         RELLIN       Read a line of input.
  1057.         SKPCBL       Skip blanks.
  1058.  
  1059.  
  1060. GETDEC
  1061.  
  1062. GETDEC reads a number as an ASCII string and converts it into binary.  The
  1063. maximum size of a binary number that it can return is two bytes.  No errors
  1064. are generated for overflows; GETDEC will return the bottom sixteen bits of
  1065. an arbitrarily large number.
  1066.  
  1067. On entry:       TEMP06          points to start of string.
  1068.                 Y               gives offset from beginning of string to
  1069.                                 start of ASCII number; no leading blanks
  1070.                                 allowed.
  1071.  
  1072. On exit:        A               contains low byte of number.
  1073.                 X               contains high byte of number.
  1074.                 Y               is updated to point to the non-numeric 
  1075.                                 character that terminated the number.
  1076.                 EQ              no number was found; A,X,Y undefined.
  1077.  
  1078.  
  1079. KINCH
  1080.  
  1081. Call this routine to get a character of input from the keyboard.  The
  1082. keyboard buffer is flushed first.  ESCAPEs are detected and acknowledged
  1083. automatically, using the OSBYTE 126 call, and the Carry flag indicates
  1084. whether ESCAPE was detected.
  1085.  
  1086. On entry:                       No entry conditions.
  1087.  
  1088. On exit:        CC              A contains input character.
  1089.                 CS              ESCAPE was detected.
  1090.  
  1091.  
  1092. MULPLY
  1093.  
  1094. MULPLY multiplies two eight bit numbers together, giving a sixteen bit
  1095. result:
  1096.  
  1097. On entry:       A               contains an 8-bit number.
  1098.                 Y               contains an 8-bit number.
  1099.  
  1100. On exit:        A               contains the low byte of the result.
  1101.                 Y               contains the high byte of the result.
  1102.                 CS              if Y is non-zero (the result is greater than
  1103.                                 255).
  1104.                 X               preserved.
  1105.  
  1106.  
  1107. OUTDEC
  1108.  
  1109. Call OUTDEC to output a sixteen bit decimal number to the VDU.
  1110.  
  1111. On entry:       X               contains the low byte of the number.
  1112.                 Y               contains the high byte of the number.  
  1113.  
  1114. On exit:        A,X,Y           undefined.
  1115.  
  1116.  
  1117. PSTRNG
  1118.  
  1119. PSTRNG outputs a string in-line with the code to the VDU.  The string must
  1120. be delimited with a null, zero byte.
  1121.  
  1122. For example:    JSR        PSTRNG
  1123.                 EQUS       "This will be output to the VDU"
  1124.                 EQUB       0
  1125.  
  1126. On entry:                  Immediately following the JSR call, there is a
  1127.                            string delimited with a null.  The string must
  1128.                            not be more then 256 characters long, including
  1129.                            the delimiter.
  1130.  
  1131. On exit:        A,Y        undefined.
  1132.                 X          preserved.
  1133.  
  1134.  
  1135. RELLIN
  1136.  
  1137. RELLIN reads a line of input, and puts it into LINBUF.  The input is
  1138. terminated with a Carriage Return or an ESCAPE.  The OSWORD 0 call is used
  1139. to get the input.  TEMP06 is left pointing to the beginning of LINBUF, and Y
  1140. gives the offset to the first non-space character in LINBUF.
  1141.  
  1142. On entry:                       No entry parameters.
  1143.  
  1144. On exit:        LINBUF          contains the line of input; maximum 256 
  1145.                                 characters.
  1146.                 TEMP06          points to LINBUF.
  1147.                 CMDPAR          gives offset from TEMP06 to the first
  1148.                                 non-space character.
  1149.  
  1150.                 CS              ESCAPE terminated input.
  1151.  
  1152.  
  1153.  
  1154. SKPCBL
  1155.  
  1156. SKPCBL skips spaces in a line of input, terminated by a Carriage Return.
  1157.  
  1158. On entry:       TEMP06          points to beginning of input string.
  1159.                 CMDPAR          gives offset from start of string to start
  1160.                                 skipping spaces.
  1161.  
  1162. On exit:        CMDPAR          gives offset to first non-space character
  1163.                                 after initial value.
  1164.                 A               contains first non-space character.
  1165.                 EQ              hit CR at end of line, before non-space
  1166.                                 character was found.
  1167.  
  1168.  
  1169. The Index System
  1170.  
  1171. The ViewStore ROM contains a set of routines for creating and maintaining
  1172. index files.  These are used internally by code in the ROM, and also by the
  1173. INDEX utility.  They are very powerful and could be used by extra utilities
  1174. to great effect.
  1175.  
  1176. You will be familiar with the way the ViewStore itself uses the index
  1177. system.  A utility could use indexes side by side with the ROM, or it could
  1178. build and maintain indexes for its own purpose.
  1179.  
  1180. In a ViewStore index file, you can store a "key", and associate with the key
  1181. a pointer value, 4 bytes in size.  They key can be any string of ASCII
  1182. characters, and the pointer value any four byte integer, but usually the
  1183. pointer value is used to remember a record file address. 
  1184.  
  1185. The characters that make up an index key must be between the values 32 and
  1186. 254, inclusive.  Since the alphabetical value of numbers and dates is not
  1187. the same as the value we generally wish these data types to have (that is
  1188. numbers in numerical order, and dates in age order), the ASCII number and
  1189. date fields as they are stored in ViewStore data files must be converted
  1190. into another form before being sent to the index system.  A routine, ADJVAL,
  1191. is provided to do this.  Remember, if you are building or altering an index
  1192. file, to use the ADJVAL routine on the key.
  1193.  
  1194. The index system uses a technique akin to that of IBM's ISAM (indexed
  1195. sequential access method) and VSAM (virtual sequential access method)
  1196. systems.
  1197.  
  1198. Nearly all the calls to alter an index file are made through one routine,
  1199. with a reason code: ISAM.
  1200.  
  1201. ISAM uses some workspace in the language workspace area.  If you're not
  1202. using the index system, the utility can use this workspace for its own
  1203. purposes.     
  1204.  
  1205. ADJVAL          Routine to adjust values of different key types.
  1206. CCRTIX          Create an index file.  
  1207. GETIXN          Return index name for a given field number. 
  1208. IDXSCH          Search for an index, given a field name. 
  1209. ISAM            General entry point to ISAM package.
  1210.  
  1211.  
  1212.  
  1213. ADJVAL
  1214.  
  1215. This routine is called before sending a key to ISAM for an operation.  It
  1216. adjusts the value of number and date fields into "index format", ready for
  1217. ISAM.
  1218.  
  1219. If you give it a date value to adjust, it will check the validity of the
  1220. date as it is processing the value.  An error code is returned if a problem
  1221. is found with the date; in this case the value left in the buffer will be
  1222. legal, but will be an incorrect conversion from the date that you supplied.
  1223.  
  1224. On entry:       X               has field number of field being adjusted.
  1225.                 LINBUF          has field value to be adjusted, delimited
  1226.                                 with an end of field marker.
  1227.  
  1228. On exit:        LINBUF          contains adjusted field value.
  1229.                 CS              error was found in date value.
  1230.  
  1231.  
  1232. CRTIX
  1233.  
  1234. CRTIX is used to create a new index file.  You must supply the name of the
  1235. file, and the number of bytes of disk space that you wish to reserve for the
  1236. file.  If a file with the name that you have exists already, it will be
  1237. overwritten.
  1238.  
  1239. The maximum amount of space that you can reserve is 65535 bytes.
  1240.  
  1241. On entry:       FBLOCK          has filename of file that you wish to create,
  1242.                                 with PREFIX already inserted.
  1243.                 A               contains keysize of file.
  1244.                 X               contains low byte of number of bytes to 
  1245.                                 reserve.
  1246.                 Y               contains high byte of number of bytes to
  1247.                                 reserve.
  1248.  
  1249. On exit:        VC              file created OK.
  1250.                 VS              error occurred; error code in A.
  1251.  
  1252.  
  1253. GETIXN
  1254.  
  1255. GETIXN extracts the name of the index for a particular field from the format
  1256. file, and places it in FBLOCK, with the index prefix automatically inserted.
  1257.  
  1258. On entry:       X               contains the field number of the field for
  1259.                                 which you require the index name.
  1260.  
  1261. On exit:        CC              no error; name is in FBLOCK with prefix.
  1262.                 CS              error occurred; error code is in A.
  1263.  
  1264.  
  1265. IDXSCH
  1266.  
  1267. Given a field name specification (which may include the wildcards "?" and
  1268. "*"), IDXSCH looks for a field with this name, and checks whether this field
  1269. has an index switched on.
  1270.  
  1271. On entry:       LWORK           contains field name to search for, which may
  1272.                                 contain wildcards.
  1273.                 A               contains field number of field to start
  1274.                                 searching from.
  1275.  
  1276. On exit:        CC              field found OK; X contains number of field
  1277.                                 found.
  1278.                 CS              no field found; error code in A.
  1279.  
  1280.  
  1281. ISAM
  1282.  
  1283. ISAM is the routine that you call to perform operations on an index file. 
  1284. The reason code of the operation you wish to perform is loaded into A.  A
  1285. summary of reason code values is given at the end in table 4.
  1286.  
  1287. All calls to ISAM update the Carry and Overflow flags.  The carry flag
  1288. indicates whether an "internal" error occurred - such as "No key found". 
  1289. The Overflow flag indicates when a filing system error occurred - such as
  1290. "Disk fault".  A list of internal ISAM errors is given in table 5.  Note
  1291. that you can't call the error reporting routine REPERL with an internal ISAM
  1292. error code; the internal code is only for checking within a program.
  1293.  
  1294. Key values are passed to ISAM in LINBUFl 4 byte pointer values are passed in
  1295. REG1.  ISAM can handle a maximum of nine indexes open at one time.  The
  1296. maximum size of a key is 105 bytes.
  1297.  
  1298. Indexed sequential files have the two features that you can locate a
  1299. particular key by giving its value, and that you can also read up and down
  1300. the index in key order.  ISAM works by having a "position".  Certain calls
  1301. set the file "position", some move the position up and down, and some calls
  1302. destroy the position altogether.  The "Search" call sets the file position;
  1303. the "Next" and "Previous" calls move the position, and the "Insert" and
  1304. "Delete" calls destroy the position.
  1305.  
  1306. If you execute a "Next", or a "Previous" call on an index file with no
  1307. position, the index is said to be set at the beginning.
  1308.  
  1309. The A, X and Y registers are all undefined after a call to ISAM.
  1310.  
  1311. Reason code     Effect
  1312.  
  1313. A=ISMFLO        Tell ISAM that file is open.
  1314.  
  1315.                 Before you make this call, you should have opened the file
  1316.                 with the filing system.  This call just informs ISAM that
  1317.                 you have opened the file, and tells it to reverse some
  1318.                 workspace for the file.
  1319.  
  1320.                 On entry:       Y       contains handle of already opened
  1321.                                         file, as returned by the filing
  1322.                                         system.
  1323.                 On exit:                The file position is reset.
  1324.                                 VS      file already open; internal error
  1325.                                         code in A.
  1326.                                 CS      internal error occurred; internal
  1327.                                         error code in A.
  1328.  
  1329. A=ISMSCH       Search for key in index.
  1330.  
  1331.                This call attempts to find the key in LINBUF in the index
  1332.                that you specify.  If no key is found, the index is still
  1333.                "positioned", and you can use the "Get next key" and "Get
  1334.                previous key" calls.  A subsequent "Get next key" call 
  1335.                after a key was not found, returns the next highest value
  1336.                key that is in the index.
  1337.  
  1338.                On entry:       Y       contains the handle of the file.
  1339.                                LINBUF  contains key to search for. 
  1340.  
  1341.                On exit:        VS      filing system error occurred; error
  1342.                                        code in A.
  1343.                                CS      key not found; internal error code in
  1344.                                        A.      
  1345.                                        The file position is set.
  1346.                                REG1    contains pointer value of key, if
  1347.                                        found.
  1348.  
  1349. A=ISMINS        Insert key into index.
  1350.  
  1351.                 This call inserts the key in LINBUF into the index file.
  1352.  
  1353.                 On entry:       Y       contains the handle of the file.
  1354.                                 LINBUF  contains the key to insert.
  1355.                                 REG1    contains pointer value to be
  1356.                                         associated with the key.
  1357.  
  1358.                 On exit:                The file position is reset.
  1359.                                 VS      filing system error occurred; error
  1360.                                         code in A.
  1361.                                 CS      index  is full; internal error code
  1362.                                         in A.
  1363.  
  1364. A=ISMNXT        Return next sequential key.
  1365.  
  1366.                 This call returns the pointer value of the next sequential
  1367.                 key, from the current file position.
  1368.  
  1369.                 On entry:       Y       contains the file handle.
  1370.  
  1371.                 On exit:        VS      filing system error occurred; error
  1372.                                         code in A.
  1373.                                 CS      At end of file; internal error code
  1374.                                         in A.  
  1375.                                         The file position is advanced by
  1376.                                         one.
  1377.                                 REG1    contains the pointer value
  1378.                                         associated with the key.
  1379.  
  1380. A=ISMDEL        Delete key from index.
  1381.  
  1382.                 This call deletes the specified key and associated pointer
  1383.                 value from the index file.
  1384.  
  1385.                 On entry:       Y       contains the file handle.
  1386.  
  1387.                 On exit:                The file position is reset.
  1388.                                 VS      filing system error occurred; error
  1389.                                         code in A.
  1390.                                 CS      Key not found; internal error code
  1391.                                         in A.
  1392.                                 REG1    contains the pointer value
  1393.                                         associated with the key.
  1394.  
  1395. A=ISMCLS        Close file.
  1396.  
  1397.                 This call closes the file; it both calls the filing system
  1398.                 to close the file, and closes the file within ISAM as well.
  1399.                 This is slightly different from the ISMOPN call, which 
  1400.                 requires the filing system open call to be separate.
  1401.  
  1402.                 On entry:       Y       contains the file handle.
  1403.  
  1404.                 On exit:        VS      filing system error occurred; error
  1405.                                         code in A.
  1406.  
  1407. A=ISMPRE        Return previous key in index file.
  1408.  
  1409.                 This call returns the pointer value of the previous 
  1410.                 sequential key in the index, from the current file position.
  1411.  
  1412.                 On entry:       Y       contains the file handle.
  1413.  
  1414.                 On exit:        VS      filing system error occurred; error 
  1415.                                         code in A.
  1416.                                 CS      Beginning of file; internal error
  1417.                                         code in A.  
  1418.                                         The file position is moved back by
  1419.                                         one.
  1420.                                 REG1    contains the pointer value
  1421.                                         associated with the key.
  1422.  
  1423.  
  1424. Printer Control Routines
  1425.  
  1426. The printer control routines handle the printer driver for the utility.  A
  1427. printer driver must be loaded from ViewStore Command Mode before calling the
  1428. utility, or the default printer driver in the ROM is used.
  1429.  
  1430. Highlights can be sent to the printer driver from a utility, but there is no
  1431. provision for handling of the printer options byte or microspacing.
  1432. Highlights begin at 128 for highlight 1.
  1433.  
  1434. A utility can test the state of the printer by examining the location
  1435. PRNFLG.  If bit 7 of PRNFLG is set, then the printer is switched on.  If bit
  1436. 6 of PRNFLG is set, then the printer is not actually on,  but waiting: a
  1437. call to PRNON will switch on the printer.
  1438.  
  1439. The printer should be switched off before reporting errors.
  1440.  
  1441.         ASKPRN          Ask about printer.
  1442.         PRNON           Switch waiting printer on.
  1443.         PRNOFF          Switch printer off.
  1444.         PSCOUTT         Send character to printer/screen vector.
  1445.  
  1446.  
  1447. ASKPRN
  1448.  
  1449. This routine prompts the user with the question "Screen or Printer (S,P)?". 
  1450. According to the response, bit 6 of PRNFLG is updated to indicate whether
  1451. the printer is waiting.  If bit 6 is set, a subsequent call to PRNON by the
  1452. utility will switch on the printer.
  1453.  
  1454. On entry:                       No entry conditions.
  1455.  
  1456. On exit:        PRNFLG          Bit 6 set if printer is waiting; clear if
  1457.                                 screen is to be used.
  1458.                 A,X,Y           undefined.
  1459.  
  1460.  
  1461. PRNON
  1462.  
  1463. If the printer is waiting, that is bit 6 of PRNFLG is set, a call to PRNON
  1464. will switch it on, calling the printer on routine in the printer driver.
  1465.  
  1466. On entry:                       No entry conditions.
  1467.  
  1468. On exit:        A,X,Y           undefined.
  1469.  
  1470.  
  1471. PRNOFF
  1472.  
  1473. If the printer is switched on, a call to PRNOFF will switch it off.
  1474.  
  1475. On entry:                       No entry conditions.
  1476.  
  1477. On exit:        PRNFLG          Bit 7 clear.  Bit 6 unaltered.
  1478.                 A,X,Y           undefined.
  1479.  
  1480.  
  1481. PSCOUT
  1482.  
  1483. This routine vectors characters either to the screen or the printer,
  1484. depending which is enabled.  A utility which wishes to use the printer
  1485. optionally should send all output to this routine, and in conjunction with
  1486. the ASKPRN, PRNON and PRNOFF calls, output can be directed by the user of
  1487. the utility to the screen or printer, depending on his answer to the ASKPRN
  1488. question.
  1489.  
  1490. PSCOTT automatically strips off trailing spaces from printer output.
  1491.  
  1492. On entry:       A               contains character to be printed.  Highlight
  1493.                                 codes begin at 128 for highlight 1.
  1494.  
  1495. On exit:        A,X,Y           preserved.
  1496.  
  1497.  
  1498. Summaries
  1499.  
  1500. Table 1 - Routines and Addresses
  1501.  
  1502.         Routine Address         Temporaries Altered
  1503.  
  1504.         PSCOTT  &802A
  1505.         KINCH   &802D
  1506.         PRNON   &8030           10
  1507.         PRNOFF  &8033           10
  1508.         ISAM    &8036           01,02,03,04,05,06,08,10,14
  1509.         FONE    &8039
  1510.         FTENFX  &803C
  1511.         FTENFQ  &803F
  1512.         FADDW1  &8042
  1513.         FTENX   &8045
  1514.         GETXFL  &8048           04,05,06,06,11
  1515.         INIIMF  &804B           00,04,05,06,07,10,11,12
  1516.         CMPFLD  &804E           01,02,03,04,05
  1517.         RELLIN  &8051           06,07,08
  1518.         FRDDK   &8054           04,05,10
  1519.         FTST    &8057
  1520.         FNEG    &805A
  1521.         FCLR    &805D
  1522.         FADDW   &8060
  1523.         FDIVA   &8063           LWORK
  1524.         FMULX   &8066 
  1525.         REPERL  &8069           04,05,06,07,10,11,12
  1526.         SETDPS  &806C
  1527.         GETFRC  &806F           04,05,06,07,11  
  1528.         OUTDEC  &8072           04,10,11
  1529.         NXTIMF&8075             03,04,05,10
  1530.         SCHFLD  &8078           02,03,04,05,06,07,11
  1531.         CHKEOR  &807B
  1532.         CHKEOF  &807E
  1533.         PSTRNG  &8081           12
  1534.         MULPLY  &8084           05,10
  1535.         GETDEC  &8087           05,10
  1536.         ADJVAL  &808A           01,02,03,04,05,06,07,10,11
  1537.         CALUTI  &808D           03,04,05,06,07,08,09,10,11,12,LWORK
  1538.         SKPCBL  &8090
  1539.         STXPRE  &8093           05
  1540.         MOVFBK  &8096     
  1541.         MOVNAY  &8099     
  1542.         CHKDIR  &809C           05
  1543.         SETDIR  &809F           04,05
  1544.         OSHCAL  &80A2
  1545.         CRTIX   &80A5
  1546.         GETKYW  &80A8           02,04,05,06,07,10,11
  1547.         IDXSCH  &80AB     
  1548.         GETIXN  &80AE
  1549.         GETWID  &80B1           04,05,06,07,10,11
  1550.         CALSBN  &80B4           04,05,06,07,10,11
  1551.         SIZFLD  &80B7     
  1552.         GETFLD  &80BA           04,05,06,07,11
  1553.         SCHFLN  &80BD           02,03,04,05,06,07,11
  1554.         ASKPRN  &80C0           06,07,08,12
  1555.         OPFILE  &80C3
  1556.         XOSCLS  &80C6
  1557.         XOSBGE  &80C9
  1558.         XOSBPU  &80CC
  1559.         XOSGBP  &80CF
  1560.         XOSARG  780D2
  1561.  
  1562.  
  1563. Table 2 - Field Numbers of the Header
  1564.  
  1565.         DIFDES 1     Description 
  1566.         DIFDSM 2     Display mode S/C
  1567.         DIFRCS 3     Record size
  1568.         DIFCAP 4     Capacity
  1569.         DIFIDX 5     Index field
  1570.         DIFSCM 6     Screen Mode
  1571.  
  1572.  
  1573. Table 3 - Field Numbers of the Format File
  1574.  
  1575.         RFFFNA 1        Name
  1576.         RFFWID 2        Width
  1577.         RFFTYP 3        Type
  1578.         RFFPOX 4        X screen position
  1579.         RFFPOY 5        Y screen position
  1580.         RFFALS 6        Scroll Y/N
  1581.         RFFDCP 7        Decimal places
  1582.         RFFRLO 8        Low limit
  1583.         RFFRHI 9        High limit
  1584.         RFFIDX 10       Index Y/N
  1585.         RFFKYW 11       Key width
  1586.         RFFIXN 12       Index name
  1587.         RFFPRO 13       Prompt
  1588.         RFFVLS 14       Value list
  1589.  
  1590.  
  1591. Table 4 - ISAM Commands
  1592.  
  1593.         ISMFLO 0        open file
  1594.         ISMSCH 1        search
  1595.         ISMINS 2        insert key
  1596.         ISMNXT 3        next key
  1597.         ISMDEL 4        delete key
  1598.         ISMCLS 5        close file
  1599.         ISMPRE 6        previous key
  1600.  
  1601.  
  1602. Table 5 - ISAM Internal Errors
  1603.  
  1604.         ISEFLO 0        file already open
  1605.         ISEKXP 1        beginning of file for previous key
  1606.         ISELSK 2        end of file for next key
  1607.         ISEKXI 3        key already exits
  1608.         ISENKF 4        no key found
  1609.  
  1610.  
  1611. Table 6 - Memory Layout
  1612.  
  1613. ViewStore variables available for read by the utility
  1614.  
  1615.         VWSLIM          &B              memory limit
  1616.  
  1617.         FILMOD          &44             editing file or not
  1618.         PRNFLG          &47             printer flag
  1619.         XSSAVE          &48             stack save for filing system
  1620.         SSAVE           &49             stack save for ISAM & FP
  1621.         CURCHN          &4A             intermediate file channel
  1622.         EFILE           &4B             main file channel
  1623.         REG1            &4C             4-byte register
  1624.  
  1625.  
  1626. Temporaries
  1627.  
  1628.         TEMPFD          &50     single byte temporaries
  1629.         TEMPFE          &51
  1630.         TEMPFF          &52
  1631.         TEMP00          &53
  1632.         TEMP01          &54
  1633.         TEMP02          &55
  1634.         TEMP03          &56
  1635.         TEMP04          &57
  1636.         TEMP05          &58
  1637.         TEMP06          &59     two byte temporaries
  1638.         TEMP07          &5B
  1639.         TEMP08          &5D
  1640.         TEMP09          &5F
  1641.         TEMP10          &61
  1642.         TEMP11          &63
  1643.         TEMP12          &65
  1644.         TEMP13          &67
  1645.         TEMP14          &69
  1646.  
  1647.         VWSSTZ          &6B      start of zero page workspace
  1648.  
  1649.         FACCS           &6B      floating point accumulator
  1650.         FACCXH          &6C
  1651.         FACCX           &6D
  1652.         FACCMA          &6E
  1653.         FACCMB          &6F
  1654.         FACCMC          &70
  1655.         FACCMD          &71
  1656.         FACCMG          &72
  1657.  
  1658.         FWRKS           &73       floating point work accumulator
  1659.         FWRKXH          &74
  1660.         FWRKX           &75
  1661.         FWRKMA          &76
  1662.         FWRKMB          &77
  1663.         FWRKMC          &78
  1664.         FWRKMD          &79
  1665.         FWRKMG          &7A
  1666.  
  1667.         VWSXTZ          &7E       start of free if using FP
  1668.  
  1669.         OSFARA          &500      OSFILE/OSHCAL work area
  1670.  
  1671.         LWORK           &50D      work area - 16 bytes
  1672.  
  1673.         FBLOCK          &563      filename work area - 27 bytes
  1674.  
  1675.         VWSSTL          &5D3      start of language workspace
  1676.         LINBUF          &5DC      line buffer/ISAM key buffer (256 bytes)
  1677.         VWSXTL          &6DC      language workspace after LINBUF
  1678.         VWSITL          &799      start of language workspace if using ISAM.
  1679.  
  1680.  
  1681. Table 7 - Offsets for Prefixes
  1682.  
  1683.         DATPRE          0         data prefix
  1684.         FMTPRE          &E        format prefix
  1685.         IDXPRE          &1C       index prefix
  1686.         SRTPRE          &2A       sort prefix
  1687.         UTIPRE          &38       utility prefix
  1688.  
  1689.  
  1690. Table 8 - Offsets for Filenames
  1691.  
  1692.         EFLNAM          &1B       data file name
  1693.         FFLNAM          &2B       format file name
  1694.         PRNAME          &35       printer name
  1695.         UTINAM          &42       utility name
  1696.         ARGNAM          &4F       name work area
  1697.  
  1698.  
  1699. Table 9 - Error Codes
  1700.  
  1701.         MEMERR          1         not enough money
  1702.         MISERR          2         mistake
  1703.         NEMERR          3         no end marker
  1704.         BDFERR          4         bad file
  1705.         ENDERR          5         end of data
  1706.         NUMERR          6         not numeric
  1707.         RANERR          7         range error
  1708.         VLSERR          8         value not in list
  1709.         TBGERR          9         overflow
  1710.         REAERR         10         read error
  1711.         RTBERR         11         record too big
  1712.         BDIERR         12         bad directory
  1713.         BDNERR         13         bad name
  1714.         FLNERR         14         field not found
  1715.         FNOERR         15         file not open
  1716.         TMFERR         16         too many files
  1717.         SKFERR         17         stack overflow
  1718.         NOFERR         18         no index field
  1719.         DATERR         19         bad date
  1720.         NFSERR         20         no fields on screen
  1721.         BDMERR         21         bad mode
  1722.         ESCERR         22         escape
  1723.         NDSERR         23         normal display
  1724.         FDSERR         24         format edit disabled
  1725.         DMOERR         25         data mode only
  1726.         BPRERR         26         bad prefix
  1727.         DCPERR         27         too many places
  1728.         FNIERR         28         field not indexed
  1729.         BDPERR         29         bad pointer
  1730.         BFSERR         30         bad FS
  1731.  
  1732.         FNXERR        127         x not found
  1733.  
  1734.  
  1735.  
  1736.  
  1737.  
  1738. Table 10 - File Format
  1739.  
  1740.         &9              end of field marker
  1741.         &D              end of record marker
  1742.         &1              end of file marker
  1743.         &3              space character
  1744.         &2              deleted character
  1745.         &0              file pad character
  1746.  
  1747. Each Field in the record is terminated by an end of field marker.  
  1748.  
  1749. Each record in the field is terminated by an end of record record.
  1750.  
  1751. The file is terminated by an end of file marker.
  1752.  
  1753. Any expansion space in a record is represented by multiple space characters
  1754. after the last end of field marker, but before the end of record marker.     
  1755.  
  1756. A deleted record is represented by multiple deleted characters followed by
  1757. an end of record marker.
  1758.  
  1759. Any padding space between the end of file marker and the physical end of
  1760. file is filled with file pad characters.